<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>添加面试需求</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
  <link rel="stylesheet" href="../layuimini/css/public.css" media="all">
</head>
<body>
<form method="post" class="layui-form" action="">
  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">需求人数</label>
      <div class="layui-input-inline">
        <input type="number" required="required" max="100" min="1" class="layui-input" name="dnumber">
      </div>
      <label type="text" style="color: red;display:none;" id="dnumber">请输入需求人数</label>
    </div>
    <br/>
    <div class="layui-inline">
      <label class="layui-form-label">岗位部门</label>
      <div class="layui-input-inline">
        <select name="deparid" class="layui-input" lay-filter="depar" >
          <option value="-1">空</option>
          <option th:each="d:${departmentList}" th:value="${d.id}" th:text="${d.name}"></option>
        </select>
      </div>
    </div>
    <br/>
    <div class="layui-inline">
      <label class="layui-form-label">岗位角色</label>
      <div class="layui-input-inline">
        <select  name="roieid" class="layui-input" id="roieid" >
          <option value="">请选择部门</option>
        </select>
      </div>
    </div>
    <br/>
    <div class="layui-inline">
      <label class="layui-form-label">岗位新角色</label>
      <div class="layui-input-inline">
        <input type="text" name="roleadd" placeholder="请输入岗位新角色" class="layui-input">
      </div>
    </div>
    <br/>
    <div class="layui-inline">
      <label class="layui-form-label">学历要求</label>
      <div class="layui-input-inline">
        <select name="degree"  class="layui-input">
          <option value="-1">请选择学历</option>
          <option value="大专">大专</option>
          <option value="本科">本科</option>
        </select>
      </div>
      <label type="text" style="color: red;display:none;" id="degree">请输入学历要求</label>
    </div>
    <br/>
    <div class="layui-inline">
      <label class="layui-form-label">工作年限</label>
      <div class="layui-input-inline">
        <input type="number" required="required" max="100" min="1" class="layui-input" name="agelimit">
      </div>
      <label type="text" style="color: red;display:none;" id="agelimit">请输入工作年限</label>
    </div>
    <br/>
    <div class="layui-inline">
      <label class="layui-form-label">招聘需求</label>
      <div class="layui-input-inline">
        <textarea name="recruitment" required="required" style="width: 190px;height: 80px"></textarea>
      </div>
      <label type="text" style="color: red;display:none;" id="recruitment">请输入招聘需求</label>
    </div>
    <br/>
    <div class="layui-inline">
      <label class="layui-form-label">招聘负责人</label>
      <div class="layui-input-inline">
        <input type="hidden" name="recruit" readonly="readonly" th:value="${ename.id}" class="layui-input">
        <input type="text" readonly="readonly" th:value="${ename.empName}" class="layui-input">
      </div>
    </div>
    <br/>
    <div class="layui-inline">
<!--      <label class="layui-form-label">面试负责人</label>-->
      <div class="layui-input-inline">
        <input type="hidden" name="demand" class="layui-input">
        <input type="hidden" id="stName" readonly="readonly" class="layui-input">
      </div>
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">添加</button>
    </div>
  </div>
</form>
<script src="../layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>


  layui.use(['form'], function () {
    var form = layui.form;
    var layer = layui.layer;
    var $ = layui.jquery;

    form.on('select(depar)',function(){
      let xin=$(":input[name='deparid']").val();
      if (xin<0){
        $(":input[name='roleadd']").val("");
        $("#stName").val("");
        return false;
      }
      let id=$(":input[name='deparid']").val();
      $.ajax({
        url:"/demand/ajaxone?id="+id,
        type:"post",
        async:false,
        success:function (data){
          $(":input[name=demand]").val(data.empname.id);
          $("#stName").val(data.empname.empName);
          $("#roieid").empty();
          $("#roieid").append(
                  "<option value='-1'>空</option>"
          );
          for (let i = 0; i < data.roles.length; i++) {
            $("#roieid").append(
                    "<option value="+data.roles[i].id+">"+data.roles[i].description+"</option>"
            );
          }
          form.render('select');
        }
      });
    });

    //监听提交
    form.on('submit(saveBtn)', function (data) {

      let dnumber=$(":input[name='dnumber']").val();
      if (dnumber<0 || dnumber>100){
        $("#dnumber").show();
        return false;
      }
      $(":input[name='dnumber']").click(function (){
        $("#dnumber").hide();
        return false;
      })

      let deparid=$("#select").val();
      if (deparid<0){
        alert("请输入部门");
        return false;
      }

      let roieid=$("#roieid").val();
      let roleadd=$(":input[name='roleadd']").val()
      if (roieid<0 && roleadd==null && roleadd==""){
        alert("岗位角色与新角色,只能为空一个");
        return false;
      }
      if (roieid>0 && roleadd!=null && roleadd!=""){
        alert("岗位角色与新角色,只能填一个");
        return false;
      }

      let degree=$(":input[name='degree']").val();
      if (degree<0){
        $("#degree").show();
        return false;
      }
      $(":input[name='degree']").click(function (){
        $("#degree").hide();
        return false;
      })

      let agelimit=$(":input[name='agelimit']").val();
      if (agelimit==null && agelimit==""){
        $("#agelimit").show();
        return false;
      }
      $(":input[name='agelimit']").click(function (){
        $("#agelimit").hide();
        return false;
      })

      let recruitment=$(":input[name='recruitment']").val();
      if (recruitment==null && recruitment==""){
        $("#recruitment").show();
        return false;
      }
      $(":input[name='recruitment']").click(function (){
        $("#recruitment").hide();
        return false;
      })
      $.post('/demand/insertdemand',data.field,function(res){
        if(res.data==="success"){
          var iframeIndex = parent.layer.getFrameIndex(window.name);
          parent.layer.close(iframeIndex);
          parent.layui.table.reload('table-user');
          parent.layer.msg(res.msg);
        }
      })
      return false;
    });
  });
</script>
</body>
</html>